/* ========================================================================
 * PROJECT: FTIR Blob Tracker
 * ========================================================================
 * This work is based on the original FTIR Blob Tracker developed by
 *   Woonhyuk Baek
 *   Woontack Woo
 *   U-VR Lab, GIST of Gwangju in Korea.
 * 
 *   http://uvr.gist.ac.kr/
 *
 * Copyright of the derived and new portions of this work
 *     (C) 2009 GIST U-VR Lab.
 *
 * This framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this framework; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact 
 *   Woonhyuk Baek
 *   <windage@live.com>
 *   GIST U-VR Lab.
 *   Department of Information and Communication
 *   Gwangju Institute of Science and Technology
 *   1, Oryong-dong, Buk-gu, Gwangju
 *   South Korea
 * ========================================================================
 ** @author   Woonhyuk Baek
 * ======================================================================== */

#ifndef _SELF_CALIBRATOR_H_
#define _SELF_CALIBRATOR_H_

#include <vector>
#include <cv.h>

#include "wMatrix.h"

namespace windage
{
	class SelfCalibrator
	{
	private:
		int gridX;
		int gridY;
		int pointCount;

		// points are normalized
		std::vector<windage::Vector2> adjustmentPoints;
		std::vector<windage::Vector2> staticPoints;
		std::vector<windage::Matrix3> homographys;

	public:
		SelfCalibrator(int GRID_X = 5, int GRID_Y = 4)
		{
			this->SetGridSize(GRID_X, GRID_Y);
		}
		~SelfCalibrator()
		{
		}

		void SetGridSize(int GRID_X, int GRID_Y);
		CvSize GetGridSize(){return cvSize(this->gridX, this->gridY);};
		inline std::vector<windage::Vector2>* GetAdjustmentPoints(){return &this->adjustmentPoints;};
		inline std::vector<windage::Vector2>* GetStaticPoints(){return &this->staticPoints;};

		bool UpdateHomography();

		// input : normalized point 0~1
		windage::Vector2 ConvertPoint(windage::Vector2 point);
	};
}

#endif